package invoicesystem.service.impl;

import invoicesystem.dao.AddressDao;
import invoicesystem.dao.impl.AddressDaoImpl;
import invoicesystem.entry.Address;
import invoicesystem.service.AddressService;

import java.util.ArrayList;

public class AddressServiceImpl implements AddressService {
    AddressDao addressDao=new AddressDaoImpl();
    @Override
    public int insertAddress(Address address) {
        return  addressDao.insertAddress(address);
    }

    @Override
    public int updateAddress(Address address) {
        return  addressDao.updateAddress(address);
    }

    @Override
    public ArrayList<Address>  select(Integer enterprise_id) {
       AddressDao addressDao=new AddressDaoImpl();
        return addressDao.select(enterprise_id);

    }

    @Override
    public Address selectByIdAndStatus(Address address) {
        AddressDao addressDao=new AddressDaoImpl();
        ArrayList<Address> addresses=addressDao.select(address.getEnterprise_id());
        //过滤具有默认属性的数据
        ArrayList<Address> list=new ArrayList<>();
        for ( Address a: addresses
             ) {
            if (a.getDefault_status().equals("默认")){
                list.add(a);
            }
        }
        return list.get(0);
    }

    @Override
    public ArrayList<Address> selectAll() {
        return addressDao.selectAll();
    }

    @Override
    public int updateStatus(Address address) {

        return addressDao.updateStatus(address);
    }
    @Override
    public ArrayList<Address> selectById(int enterprise_id) {
        return addressDao.selectById(enterprise_id);
    }

    @Override
    public Address selectByAddress(String address) {
        return addressDao.selectByAddress(address);
    }

    @Override
    public ArrayList<Address> selectAll(int id) {
        return addressDao.selectAll(id);
    }

    @Override
    public Address selectDefault(Integer enterprise_id) {
        return addressDao.selectDefault(enterprise_id);
    }
}
